import os
import subprocess

#OPTIONS
input_folder = 'C:/Users/tfree/OneDrive/Desktop/danielle_wheel_running_photometry/input_folder/'
output_folder = 'C:/Users/tfree/OneDrive/Desktop/danielle_wheel_running_photometry/output_folder/'
udf_path = 'C:/Users/tfree/OneDrive/Desktop/danielle_wheel_running_photometry'

#Collect list of file names for processing
input_files = []
for file_name in os.listdir(input_folder):
	input_files.append(file_name)
	
#Main processing loop
for file_num, file_name in enumerate(input_files):
	output_folder_check = []
	for item in os.listdir(output_folder):
		output_folder_check.append(item)
	input_handle = input_folder + file_name
	if output_folder_check == []:
		os.mkdir(output_folder + file_name[:-4] +'/')
		os.mkdir(output_folder + file_name[:-4] +'/Event_Traces/')
	if output_folder_check != [] and file_name[:-4] not in output_folder_check[0]:
                os.mkdir(output_folder + file_name[:-4] +'/')
                os.mkdir(output_folder + file_name[:-4] +'/Event_Traces/')
	output_handle = output_folder + file_name[:-4] + '/' + file_name
	trace_output_handle = output_folder + file_name[:-4] + '/Event_Traces/' + file_name
	print('Processing: ' + file_name + ' (' + str(file_num + 1)+ ' of ' +str(len(input_files))+ ')...')
	subprocess.call(['python', 'signal_check.py', input_handle, output_handle, udf_path])
	#subprocess.call(['python', 'detect_peaks.py', input_handle, output_handle, udf_path, 'time.pkl', 'df-f.pkl'])
	#subprocess.call(['python', 'quantify_peaks.py', input_handle, output_handle, udf_path, 'peak_dict.pkl', 'time.pkl', 'df-f.pkl', trace_output_handle])
	#subprocess.call(['python', 'bin_peaks.py', input_handle, output_handle, udf_path, 'peak_metrics.pkl', 'time.pkl', 'df-f.pkl'])
	
print('Done')
